<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "comment".
 *
 * @property int $comment_id 评论ID
 * @property string|null $content 评论内容
 * @property int|null $user_id 用户ID
 * @property int|null $content_id 内容ID
 * @property string|null $create_time 创建时间
 * @property string|null $update_time 更新时间
 */
class Comment extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'comment';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['comment_id'], 'required'],
            [['comment_id', 'user_id', 'content_id'], 'integer'],
            [['content'], 'string'],
            [['create_time', 'update_time'], 'safe'],
            [['comment_id'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'comment_id' => '评论ID',
            'content' => '评论内容',
            'user_id' => '用户ID',
            'content_id' => '内容ID',
            'create_time' => '创建时间',
            'update_time' => '更新时间',
        ];
    }

    public function getUser(){
        return $this->hasOne(User::class,['user_id'=>'user_id']);
    }

    public function getContent(){
        return $this->hasOne(Content::class,['content_id'=>'content_id']);
    }
}
